<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept,Authorization, Testpc,App-Version");
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
header("Content-type: text/html; charset=utf-8");

session_start();
function httpPost($url, $data) {
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    if(stripos($url,'https') === 0) {
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_COOKIESESSION, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    if($response === false) {
        echo 'Curl error: ' . curl_error($curl);
    }
    curl_close($curl);
    return $response;
}

if(!empty($_GET['type'])) {
    if(in_array($_GET['type'], array('getCaptcha', 'initCustomer',
        'authChezhu', 'drawnLottery', 'submitAddress' , 'submitApply'))) {
        echo httpPost('http://hbweixin.twomi.cn/api_hb_bjmarathon/'.$_GET['type'],$_POST);
    } else {
        echo '{"items":[],"totalCount":0,"detail":"请求参数错误","code":200,"success":false,"addon":[]}';
    }
} else {
    echo '{"items":[],"totalCount":0,"detail":"请求参数错误","code":200,"success":false,"addon":[]}';
}
